# \src\schemas\login_manager.py
from pydantic import BaseModel, Field
from typing import Optional
from datetime import datetime


# 定义登录请求模型
class LoginRequest(BaseModel):
    username: str
    password: str


class AuthManager(BaseModel):
    api_id: str
    user_id: str
    username: str
    role: Optional[str] = None
    email: str
    exp: datetime
    api_key: str
    language: Optional[str] = None


class ChangePasswordRequest(BaseModel):
    login_id: str
    old_password: str
    new_password: str
    confirm_password: str


class RefreshPasswordRequest(BaseModel):
    login_id: str
    new_password: str
    confirm_password: Optional[str] = None
    verification_code: Optional[str] = None


# Token加密资料
class LoginManager:
    def __init__(self, app_id=None,
                 api_id=None,
                 api_key=None,
                 api_name=None,
                 user_id=None,
                 username=None,
                 user_name=None,
                 token_key=None,
                 token_id=None,
                 email=None,
                 role=None):
        self.app_id = app_id
        self.api_id = api_id
        self.api_name = api_name
        self.api_key = api_key
        self.user_id = user_id
        self.username = username
        self.user_name = user_name
        self.role = role
        self.token_key = token_key
        self.token_id = token_id
        self.email = email

    def get(self):
        return {
            "app_id": self.app_id,
            "api_id": self.api_id,
            # "api_name": self.api_name,
            "api_key": self.api_key,
            "user_id": self.user_id,
            "username": self.username,
            # "user_name": self.user_name,
            "role": self.role,
            "email": self.email
        }

    def ret(self):
        return {
            # "api_id": self.api_id,
            "api_key": self.api_key,
            "api_name": self.api_name,
            "username": self.username,
            "user_name": self.user_name,
            "token_key": self.token_key,
            "role": self.role,
            "email": self.email
        }

    #登录返回资料
    def loginData(self):
        return {
            "api_id": self.api_id,
            "api_name": self.api_name,
            "user_id": self.user_id,
            "username": self.username,
            "user_name": self.user_name,
            "role": self.role,
            "email": self.email
        }

    def update_app_id(self, new_app_id):
        self.app_id = new_app_id

    def update_api_id(self, new_api_id):
        self.api_id = new_api_id

    def update_api_key(self, new_api_key):
        self.api_key = new_api_key

    def update_api_name(self, new_api_name):
        self.api_name = new_api_name

    def update_user_id(self, new_user_id):
        self.user_id = new_user_id

    def update_username(self, new_username):
        self.username = new_username

    def update_user_name(self, new_user_name):
        self.user_name = new_user_name

    def update_token_key(self, new_token_key):
        self.token_key = new_token_key

    def update_role(self, new_role):
        self.role = new_role

    def update_email(self, new_email):
        self.email = new_email
